package com.sise.stuteaintersys.controller;


import com.github.pagehelper.PageInfo;
import com.sise.stuteaintersys.bean.base.ModifyResponse;
import com.sise.stuteaintersys.bean.entity.*;
import com.sise.stuteaintersys.bean.protocol.NetResult;
import com.sise.stuteaintersys.bean.vo.*;
import com.sise.stuteaintersys.locallibs.enums.FileEnum;
import com.sise.stuteaintersys.service.LoginService;
import com.sise.stuteaintersys.service.StudentCourseService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;


/**
 * 文件名: stuteaintersys
 * 描述: 登陆控制器
 * 创建时间: 2018-12-28 14:01
 * <p>
 * 修改者：
 * 修改时间：
 * 修改内容：
 */
@RestController
@RequestMapping(value = "/student")
public class StudentController {
    @Resource
    LoginService loginService;
    @Resource
    StudentCourseService courseService;

    /**
    *@Description 用来检测学生用户的密码是否正确
    *@Param com.sise.stuteaintersys.bean.protocol.LoginRequest
    *@Return com.sise.stuteaintersys.bean.protocol.LoginResponse
    *@Date 2018/12/28
    *@Time 15:49
    */
    @PostMapping(value = "login/check")
    public LoginResponseVO checkStudent(LoginRequestVO loginRequest){
        LoginResponseVO loginResponse = loginService.checkStudent(loginRequest);
        return loginResponse;
    }

    /**
     *  检验学生注册时是否正确
     *
     *@param  registerRequset
     *@return RegisterResponseVO
     *@time 1:01
     */
    @PostMapping(value="register/check")
    public RegisterResponseVO checkRegister(RegisterRequestVO registerRequset,@DateTimeFormat(pattern="yyyy-MM-dd") Date birthday){
        RegisterResponseVO registerResponse = loginService.checkRegisterStudent(registerRequset,birthday);
        return registerResponse;
    }

    /**
     *  返回了主页的元素，有专业分向、每个分向的五条数据
     *
     *@return MainResponseVO
     *@date 2019/1/2
     *@time 1:04
     */
        @GetMapping(value = "main")
    public MainResponseVO mainResponse(){
        MainResponseVO mainResponse= courseService.responseMain();
        return mainResponse;
    }

    @GetMapping(value = "course/list")
    public NetResult listCourse(Integer pageNum, Integer pageSize, Integer id){
        PageInfo<Course> info = courseService.listCourse(pageNum,pageSize,id);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }

    /**
     *  返回已经完成的课程
     *
     *@param pageNum
     *@param pageSize
     *@param id
     *@return
     *@date 2019/1/6
     *@time 14:40
     */
    @GetMapping(value = "course/finished")
    public NetResult finishedCourse(Integer pageNum, Integer pageSize, Integer id){
        PageInfo<Course> info = courseService.finishedCourse(pageNum,pageSize,id);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }

    /**
     *  课程的主页，以及简介
     *
     *@param id
     *@return CourseMainVO
     *@date 2019/1/2
     *@time 1:06
     */
    @GetMapping(value = "course/index")
    public CourseMainVO courseMain(Integer id){
        CourseMainVO courseMainVO = courseService.getCourseBody(id);
        return courseMainVO;
    }
    /**
     *  课程的留言板
     *
     *@param pageNum
     *@param pageSize
     *@param courseId
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     */
    @GetMapping(value = "course/messages")
    public NetResult courseMessage(Integer pageNum, Integer pageSize, Integer courseId){
        PageInfo<Message> info = courseService.listMessage(pageNum,pageSize,courseId);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    /**
     *  新增留言 （加号插不进去，，）
     *
     *@param messageAddVo
     *@return Boolean
     *@date 2019/1/3
     *@time 13:34
     */
    @GetMapping(value = "course/messages/add")
    public Boolean messageAdd(MessageAddVO messageAddVo){
        Boolean status = courseService.insertMessage(messageAddVo);
        return status;
    }


    /**
     *  课程的试卷套
     *
     *@param pageNum
     *@param pageSize
     *@param courseId
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     */
    @GetMapping(value = "course/exam")
    public NetResult courseExam(Integer pageNum, Integer pageSize, Integer courseId){
        PageInfo<ExamCourse> info = courseService.listExam(pageNum,pageSize,courseId);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    
   /**
    *  试卷套的内容
    *
    *@param examType
    *@return id
    *@dateTime 2019/1/8 12:30
    */
    @GetMapping(value = "course/exam/test")
    public NetResult examTest(String examType,Integer courseId,Integer studentId){
        ExamResultVO info = courseService.listQuestion(examType,courseId,studentId);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    /**
     *  提交试卷
     *
     *@param
     *@return
     *@dateTime 2019/1/18 16:06
     */
    @PostMapping(value = "course/exam/commit")
    public ModifyResponse examCommit(ExamResult examResult){
        return courseService.insertExamResult(examResult);
    }

    /**
     *  课程的下载资源列表
     *
     *@param pageNum
     *@param pageSize
     *@param courseId
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     */
    @GetMapping(value = "course/download")
    public NetResult courseDownload(Integer pageNum, Integer pageSize, Integer courseId){
        PageInfo<DownloadInfo> info = courseService.listDownloadInfo(pageNum,pageSize,courseId);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }

    /**
     *  课程的最新作业
     *
     *@param pageNum
     *@param pageSize
     *@param courseId
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     */
    @GetMapping(value = "course/homework")
    public NetResult courseHomework(Integer pageNum, Integer pageSize, Integer courseId){
        PageInfo<Homework> info = courseService.listHomework(pageNum,pageSize,courseId);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    /**
     * 课程的全部作业
     *
     *@param pageNum
     *@param pageSize
     *@param courseId
     *@return
     *@date 2019/1/6
     *@time 15:12
     */
    @GetMapping(value = "course/homework/list")
    public NetResult listHomework(Integer pageNum, Integer pageSize, Integer courseId){
        PageInfo<HomeworkDateVO> info = courseService.AllHomework(pageNum,pageSize,courseId);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    /**
     *  一次作业的内容
     *
     *@param date
     *@return
     *@date 2019/1/6
     *@time 15:12
     */
    @GetMapping(value = "course/homework/content")
    public HomeworkResultVO getHomework(@DateTimeFormat(pattern="yyyy-MM-dd")Date date,Integer courseId,Integer studentId){
        System.out.println(date+"   "+courseId+"    "+studentId);
        HomeworkResultVO homeworkResultVO = courseService.getHomework(date,courseId,studentId);
        return homeworkResultVO;
    }

    @PostMapping(value = "course/homework/commit")
    public ModifyResponse commitHomework(@DateTimeFormat(pattern = "yyyy-mm-dd")Date datea, HomeworkResult homeworkResult){
        homeworkResult.setStatus("你已经完成作业");
        homeworkResult.setDate(datea);
        return  courseService.commitHomework(homeworkResult);
    }

/**
     *  按课程名模糊查询课程
     *
     *@param pageNum
     *@param pageSize
     *@param courseContent
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     *//*

    @GetMapping(value = "find/course")
    public NetResult courseFindCourse(Integer pageNum, Integer pageSize, String courseContent){
        PageInfo<CourseIndexResponseVO> info = courseService.findCourseByCourseName(pageNum,pageSize,courseContent);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    */
/**
     *  按老师名模糊查询课程
     *
     *@param pageNum
     *@param pageSize
     *@param teacherName
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     *//*

    @GetMapping(value = "find/teacher")
    public NetResult courseFindTeacher(Integer pageNum, Integer pageSize, String teacherName){
        PageInfo<CourseIndexResponseVO> info = courseService.findCourseByTeacherName(pageNum,pageSize, teacherName);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    */
/**
     *  按专业分类查询
     *
     *@param pageNum
     *@param pageSize
     *@param professionName
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     *//*

    @GetMapping(value = "find/profession")
    public NetResult courseFindProfession(Integer pageNum, Integer pageSize, String professionName){
        PageInfo<CourseIndexResponseVO> info = courseService.listProfessionFind(pageNum,pageSize, professionName);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    */
/**
     *  按课程分类查询
     *
     *@param pageNum
     *@param pageSize
     *@param typeName
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     *//*

    @GetMapping(value = "find/type")
    public NetResult courseFindType(Integer pageNum, Integer pageSize, String typeName){
        PageInfo<CourseIndexResponseVO> info = courseService.listCourseTypeFind(pageNum,pageSize, typeName);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
*/

    /**
     *  搜索
     *
     *@param pageNum
     *@param pageSize
     *@param course
     *@return NetResult
     *@date 2019/1/2
     *@time 1:07
     */
    @GetMapping(value = "find/content")
    public NetResult selectCourse(Integer pageNum, Integer pageSize, Course course){
        PageInfo<Course> info = courseService.selectCourse(pageNum,pageSize,course);
        return NetResult.okadddata(FileEnum.FILESUCCESS.getCode(), FileEnum.FILESUCCESS.getMessage(), info);
    }
    /**
     *  参加某门课
     *
     *@param studentCourse
     *@return
     *@dateTime 2019/1/8 12:34
     */
    @PostMapping(value = "/join/course")
    public NetResult joinCourse(StudentCourse studentCourse){
        boolean status =courseService.joinCourse(studentCourse);
        if (status){
            return NetResult.netresultok();
        }else {
            return NetResult.error(0,"已经参加");
        }
    }
}
